import request from "../../utils/request"
// pages/personal/personal.js
let startY=0 //手指起始位置
let moveY=0 //手指移动坐标
let moveDistance=0 //手指移动的距离
Page({

    /**
     * 页面的初始数据
     */
    data: {
        coverTransform:'translate(0)',
        coverTransition:'',
        userinfo:'',//用户信息
        recentPlayList:[]//用户播放记录
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let userinfo=wx.getStorageSync('userinfo')
        if(userinfo){
            this.setData({
                userinfo:JSON.parse(userinfo)
            })
        }
        this.getUserRecentPlayList(this.data.userinfo.userId)
    },
    async getUserRecentPlayList(userId){
        let recentPlayListData = await request('/user/record', {uid: userId, type: 0});
        let recentPlayList = recentPlayListData.allData.splice(0, 10)
        this.setData({
          recentPlayList
        })
      },
    handleTouchMove(e){
        moveY=e.touches[0].clientY
        moveDistance=moveY-startY

        if(moveDistance<=0){
            return
        }
        if(moveDistance>=80){
            moveDistance=80
        }
        this.setData({
            coverTransform:`translateY(${moveDistance}rpx)`
        })  
    },
    handleTouchEnd(e){
        this.setData({
            coverTransform:`translateY(0)`,
            coverTransition: 'transform 1s linear'
        })
    },
    handleTouchStart(e){
        this.setData({
            coverTransition:''
        })
        startY=e.touches[0].clientY
    },
    /* 切换到登录界面 */
    toLogin(){
        wx.navigateTo({
          url: '../login/login',
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})